package com.dqhl.community.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.activity.ApplianceCleanActivity;
import com.dqhl.community.activity.ApplianceRepairActivity;
import com.dqhl.community.activity.CommunityNoticeActivity;
import com.dqhl.community.activity.ComplainActivity;
import com.dqhl.community.activity.ExpressReceiveActivity;
import com.dqhl.community.activity.FamilyServiceActivity;
import com.dqhl.community.activity.PropertyPayActivity;
import com.dqhl.community.activity.RepairsActivity;
import com.dqhl.community.activity.ShoppingAroundActivity;
import com.dqhl.community.base.BaseFragment;

/**
 * Created by guanluocang on 2016/8/31.
 * 物业
 */
public class PropertyFragment extends BaseFragment implements View.OnClickListener {

    private TextView mTvTitle;
    private ImageView iv_property_property, iv_property_replace, iv_property_community;
    private ImageView iv_property_complain, iv_property_service, iv_property_shopping;
    private ImageView iv_property_clear, iv_property_repair, iv_property_receiver;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_property, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {

        mTvTitle = (TextView) view.findViewById(R.id.tv_top_title);
        mTvTitle.setText(R.string.txt_service);
        iv_property_property = (ImageView) view.findViewById(R.id.iv_property_property);//缴费Activity
        iv_property_replace = (ImageView) view.findViewById(R.id.iv_property_replace);//报修Activity
        iv_property_community = (ImageView) view.findViewById(R.id.iv_property_community);//社区公告Activity
        iv_property_complain = (ImageView) view.findViewById(R.id.iv_property_complain);//投诉Activity
        iv_property_service = (ImageView) view.findViewById(R.id.iv_property_service);//家政Activity
        iv_property_shopping = (ImageView) view.findViewById(R.id.iv_property_shopping);//周边购物Activity
        iv_property_clear = (ImageView) view.findViewById(R.id.iv_property_clear);//家电清洗Activity
        iv_property_repair = (ImageView) view.findViewById(R.id.iv_property_repair);//家电维修Activity
        iv_property_receiver = (ImageView) view.findViewById(R.id.iv_property_receiver);//快递代收Activity

        iv_property_property.setOnClickListener(this);
        iv_property_replace.setOnClickListener(this);
        iv_property_community.setOnClickListener(this);
        iv_property_complain.setOnClickListener(this);
        iv_property_service.setOnClickListener(this);
        iv_property_shopping.setOnClickListener(this);
        iv_property_clear.setOnClickListener(this);
        iv_property_repair.setOnClickListener(this);
        iv_property_receiver.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            //物业缴费
            case R.id.iv_property_property:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else if ("".equals(app.getAuthentication()) || app.getAuthentication() == null) {
                    toast(R.string.toast_go_to_auth);
                } else {
                    overlay(PropertyPayActivity.class);
                }
                break;
            //我要报修
            case R.id.iv_property_replace:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else if ("".equals(app.getAuthentication()) || app.getAuthentication() == null) {
                    toast(R.string.toast_go_to_auth);
                } else {
                    overlay(RepairsActivity.class);
                }
                break;
            //社区公告
            case R.id.iv_property_community:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else if ("".equals(app.getAuthentication()) || app.getAuthentication() == null) {
                    toast(R.string.toast_go_to_auth);
                } else {
                    overlay(CommunityNoticeActivity.class);
                }
                break;
            //我要投诉
            case R.id.iv_property_complain:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else if ("".equals(app.getAuthentication()) || app.getAuthentication() == null) {
                    toast(R.string.toast_go_to_auth);
                } else {
                    overlay(ComplainActivity.class);
                }
                break;
            //家政服务
            case R.id.iv_property_service:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else {
                    overlay(FamilyServiceActivity.class);
                }
                break;
            //周边购物
            case R.id.iv_property_shopping:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else if ("".equals(app.getAuthentication()) || app.getAuthentication() == null) {
                    toast(R.string.toast_go_to_auth);
                } else {
                    overlay(ShoppingAroundActivity.class);
                }
                break;
            //家电清洗
            case R.id.iv_property_clear:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else {
                    overlay(ApplianceCleanActivity.class);
                }
                break;
            //家电维修
            case R.id.iv_property_repair:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else {
                    overlay(ApplianceRepairActivity.class);
                }
                break;
            //快递代收
            case R.id.iv_property_receiver:
                if ("".equals(app.getUserId()) || app.getUserId() == null) {
                    toast("请先登录");
                } else if ("".equals(app.getAuthentication()) || app.getAuthentication() == null) {
                    toast(R.string.toast_go_to_auth);
                } else {
                    overlay(ExpressReceiveActivity.class);
                }
                break;
        }
    }
}
